//
//  RecommendGameViewCell.swift
//  SwiftDemo
//
//  Created by liguoqing on 2022/6/29.
//  Copyright © 2022 guoqing.li. All rights reserved.
//

import UIKit
import Kingfisher

class RecommendGameViewCell : UICollectionViewCell {
    
    private lazy var imgView: UIImageView = {
        let imgView = UIImageView()
        return  imgView
    }()
    
    private lazy var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.font = UIFont.systemFont(ofSize: 12)
        titleLabel.textColor = .lightGray
        return titleLabel
    }()
    
    var baseGameModel : BaseGameModel? {
        didSet{
            guard let baseGameModel = baseGameModel else { return }
            guard let iconURL = NSURL(string: baseGameModel.icon_url) else { return }
            let url = ImageResource(downloadURL: iconURL as URL)
            imgView.kf.setImage(with: url, placeholder:UIImage(named: "icon_more_btn"));
            titleLabel.text = baseGameModel.tag_name
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension RecommendGameViewCell {
    private func setupUI (){
        contentView.addSubview(imgView)
        contentView.addSubview(titleLabel)
        imgView.snp.makeConstraints { make in
            make.top.equalTo(14.5)
            make.centerX.equalTo(contentView)
            make.width.height.equalTo(45)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(imgView.snp.bottom).offset(5)
            make.centerX.equalTo(self.imgView.snp.centerX)
        }
    }
}

